package com.hui.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hui.domain.Mid;
import com.hui.domain.Song;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * @author Ayingzz
 * @create 2021/12/26 12:50
 */
public class JSONUtils {


    /**
     * Json字符串转成List<>
     * @param str
     * @param type
     * @return
     */
    public List<?> toJSONListByGson(String str, Type type) {
        Gson gson = new Gson();
        List<Mid> resList = gson.fromJson(str, type);
        return resList;
    }

    /**
     * List<>转成Json字符串
     * @param midList
     * @param type
     * @return
     */
    public String toJSONStrByGson(List<?> midList, Type type) {
        Gson gson = new Gson();
        String resStr = gson.toJson(midList, type);
        return resStr;
    }

    public Song toObjectByGson(String str, Type type) {
        Gson gson = new Gson();
        Song o = gson.fromJson(str, type);
        return o;
    }
}
